﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DelonixRegiaHMSys.Core.Interfaces;
using DelonixRegiaHMSys.Core.Models;
using DelonixRegiaHMSys.Infrastructure.Data;
using System.Data.Objects;
using System.Collections;

namespace DelonixRegiaHMSys.Infrastructure.Data
{
    public class EfGuestCreditCardDetailsQuery : GuestCreditCardDetails
    {
        public IEnumerable<GuestCreditCardDetails> GetAllCreditCardDetails()
        {
            var context = new hmsDBEntities();
            return context.guestCreditCardDetails.Select(gcc => new GuestCreditCardDetails()
            {
                creditCardNum = gcc.creditCardNum,
                cardHolderName = gcc.cardholderName,
                guestID = gcc.guestID,
                cardType = gcc.cardType,
                cardExpirationDate = gcc.cardExpirationDate
                
            });

        }
        public void AddCreditCardDetail(string creditCardNum, string cardHolderName, string guestID, string cardType, DateTime cardExpirationDate)
        {
            var context = new hmsDBEntities();
            var newCreditCardDetails = context.guestCreditCardDetails.Create();
            newCreditCardDetails.creditCardNum = creditCardNum;
            newCreditCardDetails.cardholderName = cardHolderName;
            newCreditCardDetails.guestID = guestID;
            newCreditCardDetails.cardType = cardType;
            newCreditCardDetails.cardExpirationDate = cardExpirationDate;
            context.guestCreditCardDetails.Add(newCreditCardDetails);
            context.SaveChanges();
        }
        public void DeleteCreditCardDetail(string creditCardNum)
        {
            var context = new hmsDBEntities();
            var creditcarddetailsToDelete = context.guestCreditCardDetails.FirstOrDefault(d => d.creditCardNum == creditCardNum);
            context.guestCreditCardDetails.Remove(creditcarddetailsToDelete);
            context.SaveChanges();
        }
    }
}
